Repository navigation
feat(go): presets and embedding shortlist - #1307
Conversation
Ports laya/presets.py and the embedding shortlist of laya/shortlist.py (Rank, Predict, Cached, StateField, presets) with Python goldens, a real-weights e2e against ONNXAgent, and CI floor 1603 -> 1667. One commit so the regenerated goldens and the tests that read them land together.
Three things my conflict resolution got wrong across #1306, #1307, #1308, #1309, #1310 and #1311, which all touch go.yml, README.md, gen_go_fixtures.py and go_extra.json: 1. `shortlist_order_family` lost its `return {"cases": cases}`. The conflict boundary fell on that line, so the function built its cases and returned None, and go_extra.json carried `"shortlist_order": null`. Found by parsing the merged file and checking all 98 top-level names against the PR each came from; only this one and `build` failed, and `build` is the validated union of all 23 keys. 2. go.yml lost four of #1309's parity steps (the samples module's golden check, build, test and no-cgo build). #1310 conflicted over the same hunk and my resolver kept one side. Restored; the merged file now holds every step name from every PR in the series and none that is not in one of them. 3. `build()` had `email_fuzz` ahead of `router`. They are the only two of the new families that draw from the shared `rng`, so that order re-drew the corpus #1311 recorded `router.signatures` from, and `router/golden_test.go` pins how many of those 107 signatures come out byte-identical to Python's: 42 instead of 50. Nothing was wrong with that constant, or with Go. Putting `router` first gives it the stream #1311 measured, and `email_fuzz` is the one re-drawn, which it can be: it has no such constant, only a 1500-case count, and it still holds 1500. With that, `gen_go_fixtures.py --check` passes and each PR's own key reproduces verbatim from this tree: calibration (#1306), shortlist_order (#1307), email_fold (#1308) and router (#1311). `go build`, `go vet` and `go test` are green across all 12 packages. `--min-tests` is left at 3869 as a floor rather than an exact count, because the figure a full lane reports cannot be measured here: several goldens need ONNX exports. The comment says so and asks for it to be tightened on the next green run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged into 0.4.14. Presets and the embedding shortlist together is a sensible pair: the shortlist is the thing the docs tell people to reach for past roughly 20 options, and a port that has presets but no way to narrow a large label space leaves the user at exactly the point where the model degrades.
You should know that my resolution of the Green: |
Based on
main.What and why
presetsTriage,Email,EmailWith,Guard,Moderation,Router,All,StateField:laya/presets.pyshortlistRank,RankWithInstructions,Choice,Predict,QueryText:shortlist_choiceandpredict_shortlistshortlistCached/CachedEmbedder(Embed,Info,Clear):cached_embed_fnschemaQuestion.Subset(indices):_subset_criteriafor a typed question; drops the option orderpresets.jsonandshortlist.jsonregenerated per commit; floor 1603 -> 1667Out of scope:
predict_tournament,embed_fn_from_agent(the ONNX session exposes only the decision head), the router, calibration.Differences from Python
schema.Questionand a call's keywords areagent.CallOption;Predicttakes anyPredictor(*agent.Agent).Embedderisfunc(ctx, []string) ([][]float64, error). Python's "not callable", "not an array" and "wrong ndim" refusals reduce to a nil embedder (only when a ranking is needed), a wrong row count, an empty row, or rows of different widths (ErrEmbedding).int>= 1 (ErrInvalidArgument); Python'sbooland non-int refusals cannot occur. Empty, duplicated or wrongly typed criteria are refused when theQuestionis built.RuntimeWarningfor a droppedoption_orderisShortlisted.Warnings, same wording.Ranking.Labelsareschema.Label(the original key type);Indicesadds their positions.EmailWithtakes[]schema.Option(a Go map has no order); empty or nil is the defaults, as Python'scategories or {...}.StateFieldtakes typed questions, which always have instructions; Python raises on a definition without them.predict_tournamentis not ported.Cachedstores float32 rows as Python does; a drift in dimension is refused as Python refuses it.Evidence
Goldens (all from Python)
presets.jsonis_phishingcriteria order, guardtopiccriteria list vs dict; the model input is identical), custom and empty email categories,state_fieldper preset and 9 hostile specsshortlist.jsonpredict_shortlistcasesgo_extra.jsonshortlist_orderoption_orderkept on passthrough and non-choice, dropped and warned on a narrowed choice, one warning per questionReal-weights e2e (multilingual fused graph, hashing embedder
laya-rust/tools/hashing_embedder.py)shortlist.Predictvs Pythonpredict_shortlistonONNXAgent: 5 states x k in {1,3,5,8,17,99} x {plain, cached} = 60 calls, 6 choice questions, one withoption_order, plus noul and scoreStateFieldon triage and routerMutants
k > nk < 0float64()conversion removed== nil\wcount < 1Scanners and review
pending